﻿using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Utilities.Tests
{
    [TestClass()]
    public class NumberGeneratorTest
    {
        private TestContext testContextInstance;

        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        /// <summary>
        /// Tests the range of the generated numbers without taking into account the digit length
        /// </summary>
        [TestMethod()]
        public void GenerateNumberWithoutDigitRestrictionsTest()
        {
            /* Byte */
            Assert.IsTrue(NumberGenerator.Generate(NumberGenerator.Types.Byte).IsBetween(byte.MinValue, byte.MaxValue));

            /* SByte */
            Assert.IsTrue(NumberGenerator.Generate(NumberGenerator.Types.SByte).IsBetween(sbyte.MinValue, sbyte.MaxValue));

            /* Int16 */
            Assert.IsTrue(NumberGenerator.Generate(NumberGenerator.Types.Int16).IsBetween(short.MinValue, short.MaxValue));

            /* UInt16 */
            Assert.IsTrue(NumberGenerator.Generate(NumberGenerator.Types.UInt16).IsBetween(ushort.MinValue, ushort.MaxValue));

            /* Int32 */
            Assert.IsTrue(NumberGenerator.Generate(NumberGenerator.Types.Int32).IsBetween(int.MinValue, int.MaxValue));
        }

        /// <summary>
        /// Tests the range of the generated numbers without taking into account the digit length
        /// </summary>
        [TestMethod()]
        public void GenerateNumberWithoutDigitRestrictionsWithTypeNameTest()
        {
            /* Byte */
            Assert.IsTrue(NumberGenerator.Generate("System.Byte").IsBetween(byte.MinValue, byte.MaxValue));

            /* SByte */
            Assert.IsTrue(NumberGenerator.Generate("System.SByte").IsBetween(sbyte.MinValue, sbyte.MaxValue));

            /* Int16 */
            Assert.IsTrue(NumberGenerator.Generate("System.Int16").IsBetween(short.MinValue, short.MaxValue));

            /* UInt16 */
            Assert.IsTrue(NumberGenerator.Generate("System.UInt16").IsBetween(ushort.MinValue, ushort.MaxValue));

            /* Int32 */
            Assert.IsTrue(NumberGenerator.Generate("System.Int32").IsBetween(int.MinValue, int.MaxValue));
        }

        /// <summary>
        /// Tests the range of the generated numbers without taking into account the digit length
        /// </summary>
        [TestMethod()]
        public void GenerateNumberWithDigitRestrictionsTest()
        {
            /* Byte */
            Assert.IsTrue(NumberGenerator.Generate(NumberGenerator.Types.Byte, 2).IsBetween(10, 99));
            Assert.IsTrue(NumberGenerator.Generate(NumberGenerator.Types.Byte, 2) > 9);
            Assert.IsTrue(NumberGenerator.Generate(NumberGenerator.Types.Byte, 2) < 100);

            Assert.IsTrue(NumberGenerator.Generate(NumberGenerator.Types.Byte, 3).IsBetween(100, byte.MaxValue));
            Assert.IsTrue(NumberGenerator.Generate(NumberGenerator.Types.Byte, 3) > 99);
            Assert.IsTrue(NumberGenerator.Generate(NumberGenerator.Types.Byte, 3) < byte.MaxValue + 1);

            Assert.IsTrue(NumberGenerator.Generate(NumberGenerator.Types.Byte, 4).IsBetween(100, byte.MaxValue)); // Greater than the max length of the type
            Assert.IsTrue(NumberGenerator.Generate(NumberGenerator.Types.Byte, 4) > 99);
            Assert.IsTrue(NumberGenerator.Generate(NumberGenerator.Types.Byte, 4) < byte.MaxValue + 1);

            /* SByte */
            Assert.IsTrue(NumberGenerator.Generate(NumberGenerator.Types.SByte, 2).IsBetween(10, 99));
            Assert.IsTrue(NumberGenerator.Generate(NumberGenerator.Types.SByte, 2) > 9);
            Assert.IsTrue(NumberGenerator.Generate(NumberGenerator.Types.SByte, 2) < 100);

            Assert.IsTrue(NumberGenerator.Generate(NumberGenerator.Types.SByte, 3).IsBetween(100, sbyte.MaxValue));
            Assert.IsTrue(NumberGenerator.Generate(NumberGenerator.Types.SByte, 3) > 99);
            Assert.IsTrue(NumberGenerator.Generate(NumberGenerator.Types.SByte, 3) < sbyte.MaxValue + 1);

            Assert.IsTrue(NumberGenerator.Generate(NumberGenerator.Types.SByte, 4).IsBetween(100, sbyte.MaxValue)); // Greater than the max length of the type
            Assert.IsTrue(NumberGenerator.Generate(NumberGenerator.Types.SByte, 4) > 99);
            Assert.IsTrue(NumberGenerator.Generate(NumberGenerator.Types.SByte, 4) < sbyte.MaxValue + 1);

            /* Int16 */
            Assert.IsTrue(NumberGenerator.Generate(NumberGenerator.Types.Int16, 2).IsBetween(10, 99));
            Assert.IsTrue(NumberGenerator.Generate(NumberGenerator.Types.Int16, 2) > 9);
            Assert.IsTrue(NumberGenerator.Generate(NumberGenerator.Types.Int16, 2) < 100);

            Assert.IsTrue(NumberGenerator.Generate(NumberGenerator.Types.Int16, 5).IsBetween(10000, short.MaxValue));
            Assert.IsTrue(NumberGenerator.Generate(NumberGenerator.Types.Int16, 5) > 9999);
            Assert.IsTrue(NumberGenerator.Generate(NumberGenerator.Types.Int16, 5) < short.MaxValue + 1);

            Assert.IsTrue(NumberGenerator.Generate(NumberGenerator.Types.Int16, 6).IsBetween(10000, short.MaxValue)); // Greater than the max length of the type
            Assert.IsTrue(NumberGenerator.Generate(NumberGenerator.Types.Int16, 6) > 9999);
            Assert.IsTrue(NumberGenerator.Generate(NumberGenerator.Types.Int16, 6) < short.MaxValue + 1);

            /* UInt16 */
            Assert.IsTrue(NumberGenerator.Generate(NumberGenerator.Types.UInt16, 2).IsBetween(10, 99));
            Assert.IsTrue(NumberGenerator.Generate(NumberGenerator.Types.UInt16, 2) > 9);
            Assert.IsTrue(NumberGenerator.Generate(NumberGenerator.Types.UInt16, 2) < 100);

            Assert.IsTrue(NumberGenerator.Generate(NumberGenerator.Types.UInt16, 5).IsBetween(10000, ushort.MaxValue));
            Assert.IsTrue(NumberGenerator.Generate(NumberGenerator.Types.UInt16, 5) > 9999);
            Assert.IsTrue(NumberGenerator.Generate(NumberGenerator.Types.UInt16, 5) < ushort.MaxValue + 1);

            Assert.IsTrue(NumberGenerator.Generate(NumberGenerator.Types.UInt16, 6).IsBetween(10000, ushort.MaxValue)); // Greater than the max length of the type
            Assert.IsTrue(NumberGenerator.Generate(NumberGenerator.Types.UInt16, 6) > 9999);
            Assert.IsTrue(NumberGenerator.Generate(NumberGenerator.Types.UInt16, 6) < ushort.MaxValue + 1);

            /* Int32 */
            Assert.IsTrue(NumberGenerator.Generate(NumberGenerator.Types.Int32, 2).IsBetween(10, 99));
            Assert.IsTrue(NumberGenerator.Generate(NumberGenerator.Types.Int32, 2) > 9);
            Assert.IsTrue(NumberGenerator.Generate(NumberGenerator.Types.Int32, 2) < 100);

            Assert.IsTrue(NumberGenerator.Generate(NumberGenerator.Types.Int32, 5).IsBetween(10000, 99999));
            Assert.IsTrue(NumberGenerator.Generate(NumberGenerator.Types.Int32, 5) > 9999);
            Assert.IsTrue(NumberGenerator.Generate(NumberGenerator.Types.Int32, 5) < 100000);

            Assert.IsTrue(NumberGenerator.Generate(NumberGenerator.Types.Int32, 12).IsBetween(1000000000, int.MaxValue)); // Greater than the max length of the type
            Assert.IsTrue(NumberGenerator.Generate(NumberGenerator.Types.Int32, 12) > 999999999);
            Assert.IsTrue(NumberGenerator.Generate(NumberGenerator.Types.Int32, 12) <= int.MaxValue);
        }
    }
}
